package com.xps.and.yuntong.Data.net;



import com.xps.and.yuntong.Data.serviceapi.UserApi;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public abstract class RetrofitUtils {
    //版本更新不用改
    public static final String ROOTGX = "http://60.205.149.135/v1";
    //线下
    //public static final String ROOT = "http://60.205.149.135:8080/v1";
    //线上
    public static final String ROOT = "http://api.xn--uu-df3cl18z.com/v1";


    //韵童线下
    public static final String ROOTYT = "http://api.yuntontech.com/v1";

    protected static UserApi userApi = null;
    protected static UserApi userApiYt = null;
    protected static UserApi payApiGX = null;
    protected static OkHttpClient okHttpClient = OkhttpUtils.getOkHttpClient();

    protected static UserApi getUserApi() {
        if (null == userApi) {
            Retrofit mRetrofit = new Retrofit.Builder()
                    .baseUrl(ROOT + "/")
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .client(okHttpClient)
                    .build();
            userApi = mRetrofit.create(UserApi.class);
        }
        return userApi;
    }

    protected static UserApi getUserApiYt() {
        if (null == userApiYt) {
            Retrofit mRetrofit = new Retrofit.Builder()
                    .baseUrl(ROOTYT + "/")
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .client(okHttpClient)
                    .build();
            userApiYt = mRetrofit.create(UserApi.class);
        }
        return userApiYt;
    }


    protected static UserApi getPayApiGX() {
        if (null == payApiGX) {
            Retrofit mRetrofit = new Retrofit.Builder()
                    .baseUrl(ROOTGX + "/")
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .client(okHttpClient)
                    .build();
            payApiGX = mRetrofit.create(UserApi.class);
        }
        return payApiGX;
    }
}